package cn.xmkeshe.controller;

import cn.xmkeshe.back.IItemServiceBack;
import cn.xmkeshe.front.IItemServiceFront;
import cn.xmkeshe.model.Cars;
import cn.xmkeshe.model.Item;
import cn.xmkeshe.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
public class ItemController {

  @Resource
  private IItemServiceBack iItemServiceBack;
  @Resource
  private IItemServiceFront iItemServiceFront;


//  添加货物类型
  @RequestMapping("/pages/back/item/addPre")
  @Log(operationName = "添加货物类型前",operationType = "管理员")
  public String addPre(){
    return "/pages/back/item/add";
  }

  @RequestMapping("/pages/back/item/add")
  @ResponseBody
  @Log(operationName = "添加货物类型",operationType = "系统")
  public String add(Item item){
    String flag = "error";
    if(iItemServiceBack.add(item)){
      return "success";
    }
    return flag;
  }

//  查询货物类型页面
  @RequestMapping("/pages/back/item/listPre")
  @Log(operationName = "查询货物类型页面",operationType = "管理员")
  public String listPre(){
    return "/pages/back/item/list";
  }

  @RequestMapping("/pages/back/item/list")
  @ResponseBody
  @Log(operationName = "货物类型数据",operationType = "系统")
  public Map<String,Object> list(Item item){
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("code",0);
    map.put("msg","加载中");
    map.put("data",iItemServiceBack.findAll());
    map.put("count",1000);
    return map;
  }

//  所有货物类型
  @RequestMapping("/pages/front/item/listall")
  @ResponseBody
  @Log(operationName = "所有货物类型",operationType = "系统")
  public List<Item> listall(Item item){
    return iItemServiceFront.list();
  }

//  删除货物
  @RequestMapping("/pages/back/item/delete")
  @ResponseBody
  @Log(operationName = "删除货物",operationType = "管理员")
  public String delete(String iid){
    String flag = "error";
    if(iItemServiceBack.delete(iid)){
      return "success";
    }
    return flag;
  }


//  修改货物描述
  @RequestMapping("/pages/back/item/edit")
  @ResponseBody
  @Log(operationName = "修改货物描述",operationType = "管理员")
  public String editNote(String note,String iid){
    String flag = "error";
    if (iItemServiceBack.editNote(note,iid)){
      return "success";
    }
    return flag;
  }
}
